package com.branches.imgs;

import net.coobird.thumbnailator.Thumbnails;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author wujian
 * @date 2024/5/22
 */
public class OCRExamItem {
    /**
     * 主键
     */
    private long itemId;
    /**
     * 识别结果
     */
    private String recognitionValue;


    private float probability;

    /**
     * 图片地址
     */
    private String url;

    private File file;

    private Thumbnails.Builder<File> image;

    private int width;

    private int height;

    private long size;

    public Thumbnails.Builder<File> getImage() {
        return image;
    }

    public void setImage(Thumbnails.Builder<File> image) {
        this.image = image;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public void init() {
        try {
            recognitionValue = "";
            image = Thumbnails.of(file).scale(1.0);
            BufferedImage bufferedImage = image.asBufferedImage();
            width = bufferedImage.getWidth();
            height = bufferedImage.getHeight();
            size = file.length();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public long getItemId() {
        return itemId;
    }

    public void setItemId(long itemId) {
        this.itemId = itemId;
    }

    public String getRecognitionValue() {
        return recognitionValue;
    }

    public void setRecognitionValue(String recognitionValue) {
        this.recognitionValue = recognitionValue;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int sort(OCRExamItem item) {
        int disHeight = this.getHeight() - item.getHeight();
        if (disHeight != 0) {
            return disHeight;
        } else {
            return this.getWidth() - item.getWidth();
        }
    }
}
